/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servlet;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

import business.RegisterMember;
import data.RegisterMemberDBase;

/**
 *
 * @author User
 */
public class RegisterMemberServlet extends HttpServlet {

    protected void doPost(HttpServletRequest request,
            HttpServletResponse response)
            throws ServletException, IOException {
        // get parameters from the request
        String nama = request.getParameter("nama");
        String jk = request.getParameter("jk");
        String pass = request.getParameter("pass");
        String email = request.getParameter("email");

        // create the User object
        RegisterMember user = new RegisterMember();
        user.setNama(nama);
        user.setJk(jk);
        user.setEmail(email);
        user.setPass(pass);

        String url = "";
        String message = "";

        if (RegisterMemberDBase.cekMember(email)) {
            //if (true == true) {
            RegisterMemberDBase.InsertMember(nama, jk, email, pass);
            message = "Success please login";
            url = "/home.jsp";
        } else {
            message = "you've registered yet!";
            url = "/register.jsp";
        }

        // store the user and message in the session
        HttpSession session = request.getSession();
        session.setAttribute("user", user);
        request.setAttribute("message", message);

        // forward the request and response to the view
        RequestDispatcher dispatcher =
                getServletContext().getRequestDispatcher(url);
        dispatcher.forward(request, response);
    }
}
